package org.springbus.ff.filter;

import lombok.ToString;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;

public class Filter {

    public String outputs;
    private String name;
    public List<String> inputs;

    private Map<String, Object> options;

    public Filter(String filter, Map<String, Object> options) {
        this.name = filter;
        this.options = options;
    }

    public String getName() {
        return name;
    }
    public Map<String, Object> getOptions(){
        return options;
    }
    public String  getOptionKey(String k){
        return options.get(k)+"";
    }

    public String  toString(){
        StringBuilder sb=new StringBuilder();
        StringJoiner joiner=new StringJoiner(":");
        for(String key : options.keySet()){
            if(options.get(key)!=null){
                Object v=options.get(key);
                if(v instanceof  String ){
                    joiner.add(key + "='"+v.toString()+"'");
                }else {
                    joiner.add(key + "=" +v.toString());
                }
            }
        }
        if(inputs!=null && inputs.size()>0){
            for(String in: inputs) {
                sb.append("[").append(in).append("]");
            }
        }
        sb.append(name);
        if(joiner.length()>0){
            sb.append("=").append(joiner.toString());
        }
        if(outputs!=null){
            sb.append("[").append(outputs).append("]");
        }
        return sb.toString();
    }

    public void setOutputs(String outputs) {
        this.outputs=outputs;
    }

    public void setInputs(List<String> list) {
        this.inputs=list;
    }
}
